//
//  WBNavigationController.swift
//  XLWB
//
//  Created by MacBook on 16/6/29.
//  Copyright © 2016年 MacBook. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
   override func viewDidLoad() {
        //隐藏默认的Bar
        navigationBar.isHidden = true
    }
    
    
   //重写push方法,所有的push动作都会调用
   override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //如果不是栈底控制器才需要隐藏,根控制器不需要处理
        if childViewControllers.count > 0 {
            //隐藏底部的taBar
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    
                    //显示首页标题
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack: true)
            }
            
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func popToParent() {
    
    
        popViewController(animated: true)
    
    }
    
}
